package com.example.wechat.util;

import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.request.target.ImageViewTarget;
import com.bumptech.glide.request.transition.Transition;

public class ProgressTarget<D> extends ImageViewTarget<Drawable> {
    private ProgressListener listener;

    public interface ProgressListener {
        void onProgress(int progress);
    }

    public ProgressTarget(ImageView view) {
        super(view);
    }

    public void setProgressListener(ProgressListener listener) {
        this.listener = listener;
    }

    @Override
    public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
        super.onResourceReady(resource, transition);
        if (listener != null) {
            listener.onProgress(100);
        }
    }

    @Override
    protected void setResource(@Nullable Drawable resource) {

    }

    public void onProgressUpdate(int progress) {
        if (listener != null) {
            listener.onProgress(progress);
        }
    }
} 